﻿
using UnityEngine;
using WorldMapBase.Tile.Pool;

namespace Yoozoo.Gameplay.Liberty.Pool
{
    public class EffectPrefabPool : ObjectPool<Transform>
    {
        private int _initNum;
        protected GameObject _originObject;

        public int Type { get; private set; }
        
        public EffectPrefabPool(int initNum, int capacity,int type, GameObject originObject) : 
            base(capacity,true,10,5,10)
        {
#if UNITY_EDITOR
            _name = "街道动态对象池: " + originObject.name;
#endif
            Type = type;
            _initNum = initNum;
            _originObject = originObject;
        }


        public void PreInit()
        {
            OnInit(_initNum);
        }
        
        protected override Transform ConstructItem()
        {
            if (_originObject == null)
            {
                UnityEngine.Debug.LogError("EffectPrefabPool ConstructItem _originObject is nil");
                return null;
            }
            
            Transform objTransform = 
                GameObject.Instantiate(_originObject, Vector3.zero, Quaternion.identity,LibertyPoolMgr.GetInstance("LibertyPoolMgr").EffectRoot).transform;
            objTransform.gameObject.SetActive(false);
            return objTransform;
        }
        
        protected override void BeforeRecover(Transform obj)
        {
            obj.gameObject.SetActive(false);
        }

        protected override void OnRemoveItem(Transform trans)
        {
            GameObject.Destroy(trans.gameObject);
        }

        public override void Destroy()
        {
            base.Destroy();
            _originObject = null;
        }
        
    }
}